package ${packageName}.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import ${packageName}.entity.${className};
import ${packageName}.service.${className}Service;


/**
*  @author   ${author!'admin'}
*/
@Controller
@RequestMapping(value = "/${className1}/${className1}")
public class ${className}Controller {

    @Autowired
    private ${className}Service ${className1}Service;

    @RequestMapping(value = "list")
    public String list(${className} ${className1}, HttpServletRequest request, HttpServletResponse response, Model model) {
        List<${className}> list =${className1}Service.findList(${className1});
        model.addAttribute("list", list);
        return "跳转路径";
    }

    @RequestMapping(value = "form")
    public String form(${className} ${className1}, HttpServletRequest request, HttpServletResponse response, Model model) {
        //方法一: 根据id查询  请根据需求使用方法,${className1}.getId请根据实际id名称获取
        //${className} ${className1}=${className1}Service.get(${className1}.getId);
        //或者
        //String id=request.getParameter("id");
        //${className} ${className1}=${className1}Service.get(id);
        //方法二: 根据实体字段查询
        ${className} ${className1}=${className1}Service.get(${className1});
        model.addAttribute("${className1}", ${className1});
        return "跳转路径";
    }

    @RequestMapping(value = "save")
    //	@ResponseBody  如果要返回字符串取消该注释
    public String save(${className} ${className1}, HttpServletRequest request, HttpServletResponse response, Model model) {
        ${className1}Service.insert(${className1});
        return "跳转路径/返回参数";
    }

    @RequestMapping(value = "update")
    //	@ResponseBody  如果要返回字符串取消该注释
    public String save(${className} ${className1}, HttpServletRequest request, HttpServletResponse response, Model model) {
        ${className1}Service.update(${className1});
        return "跳转路径/返回参数";
    }

    @RequestMapping(value = "delete")
    //	@ResponseBody  如果要返回字符串取消该注释
    public String delete(${className} ${className1}, HttpServletRequest request) {
        //方法一: 根据id删除  请根据需求使用方法,${className1}.getId请根据实际id名称获取
        //${className} ${className1}=${className1}Service.delete(${className1}.getId);
        //或者
        //String id=request.getParameter("id");
        //${className} ${className1}=${className1}Service.delete(id);
        //方法二: 根据实体字段删除
        ${className1}Service.delete(${className1});
        return "跳转路径/返回参数";
    }

    }